home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: axcdf1.pd.infn.it!LORETI
- From: loreti@axcdf1.pd.infn.it (Maurizio Loreti)
- Subject: Re: array[index]
- X-Nntp-Posting-Host: axcdf1.pd.infn.it
- Message-ID: <DpnG4p.3xr@news.cern.ch>
- Sender: news@news.cern.ch (USENET News System)
- Reply-To: loreti@axcdf1.pd.infn.it
- Organization: I.N.F.N. Padova - CDF/CMS VAXcluster
- References: <4jiies$3bh@fnord.dfw.net>
- Date: Wed, 10 Apr 1996 14:57:59 GMT
-
- In article <4jiies$3bh@fnord.dfw.net>, ftlgeuse@dfw.dfw.net (Azazel Diabolus (aka Fetelgeuse)) writes:
- >On my platform's assembly language a[n] is the same as n[a]; is this also
- >valid in C? Does array[index] give the same address as index[array]? I
- >will try this after I post it but I would like to know if this is
- >something defined by the ANSI standard. Thanks,
- >Fetelgeuse
-
- Checking the FAQ list before posting, you accidentally skipped Q/A
- 6.11; here it is:
-
- 6.11: I came across some "joke" code containing the "expression"
- 5["abcdef"] . How can this be legal C?
-
- A: Yes, Virginia, array subscripting is commutative in C. This
- curious fact follows from the pointer definition of array
- subscripting, namely that a[e] is identical to *((a)+(e)), for
- *any* two expressions a and e, as long as one of them is a
- pointer expression and one is integral. This unsuspected
- commutativity is often mentioned in C texts as if it were
- something to be proud of, but it finds no useful application
- outside of the Obfuscated C Contest (see question 20.36).
-
- References: Rationale Sec. 3.3.2.1; H&S Sec. 5.4.1 p. 124,
- Sec. 7.4.1 pp. 186-7.
-
- --
- Maurizio Loreti http://mvxpd5.pd.infn.it/wwwcdf/mlo.html
- Un. of Padova, Dept. of Physics - Padova, Italy loreti@padova.infn.it
-